﻿#coding=utf-8
from django import template

register = template.Library()

@register.filter(name='truncatechar')
def truncatechar(s, num):
    "Truncates a string after a certain number of chars."
    length = int(num)
    if len(s) > length:
        s = s[:length]
        if not s.endswith('...'):
            s += '...'
    return s



@register.filter(name='chinese')
def chinese(s):
    
    if s == 'soft':
        s = '软件'
    if s == 'game':
        s = '游戏'
    if s == 'book':
        s = '小说'
    return s

@register.filter(name='english')
def english(s):
    
    if s == '软件':
        s = 'soft'
    if s == '游戏':
        s = 'game'
    if s == '小说':
        s = 'book'
    return s